package com.wn.common.dialog

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import com.blankj.utilcode.util.ScreenUtils
import com.wn.common.databinding.DialogLogoutBinding
import com.wn.framework.base.BaseDialog
import com.wn.framework.base.BaseDialogFragment
import com.wn.framework.ext.onClick

/**
 * @Author: wn
 * @Date: 2025/8/6 16:24
 * @Description: 退出登陆 弹框
 */
class LogoutTipsDialog {
  class Builder(
    activity: FragmentActivity,
    private var mButtonClickListener: (() -> Unit)? = null,
  ) : BaseDialogFragment.Builder<Builder>(activity) {
    /**
     * 此处为实例 的 XML 布局
     */
    private val mBinding: DialogLogoutBinding =
      DialogLogoutBinding.inflate(LayoutInflater.from(context))

    init {
      initView()
    }

    private fun initView() {
      // 绑定 实例 布局
      setContentView(mBinding.root)
      setWidth((ScreenUtils.getScreenWidth() * 0.8).toInt())
      setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
      setAnimStyle(BaseDialog.AnimStyle.TOAST)
      setCanceledOnTouchOutside(true)
      // 确认  调用 传入的 lambda
      mBinding.tvApplyReturn.onClick {
        mButtonClickListener?.invoke()
        dismiss()
      }
      // 取消 直接 dismiss
      mBinding.tvCancel.onClick {
        dismiss()
      }
    }
  }
}